﻿using MediatR;
using RBAC.Common.Domains.RabbitProject;
using RBAC.Common.Dto;
using RBAC.Common.infrastructures.interfaces;
using RBAC.Enum;

namespace RBAC.api.Application.commond.culture
{
    public class ProductionBasicMessHander : IRequestHandler<ProductionBasicMessCommond, Rulst>
    {


        private readonly IbaseRpository<ProductionBasicMess> _ProductionBsicMess;

        public ProductionBasicMessHander(IbaseRpository<ProductionBasicMess> productionBsicMess)
        {
            _ProductionBsicMess = productionBsicMess;
        }

        public async Task<Rulst> Handle(ProductionBasicMessCommond request, CancellationToken cancellationToken)
        {
            var query = new Rulst() { Code = (int)Reult.success };


            var result = _ProductionBsicMess.Query().Where(x => x.ProDuctionNum == request.GEtProductionBasicMess.ProDuctionNum
            && x.ProDuctionenterprise == request.GEtProductionBasicMess.ProDuctionenterprise
            && x.expirationtime == request.GEtProductionBasicMess.expirationtime
            &&x.ProDuctionImages==request.GEtProductionBasicMess.ProDuctionImages
            &&x.ProductionBath==request.GEtProductionBasicMess.ProductionBath
            &&x.Goodsid==request.GEtProductionBasicMess.Goodsid
            ).FirstOrDefault();

            if(result!=null)
            {
                var GTPro= new ProductionBasicMess() {
                    expirationtime=request.GEtProductionBasicMess.expirationtime,
                    Goodsid=request.GEtProductionBasicMess.Goodsid,
                    ProductionBath=request.GEtProductionBasicMess.ProductionBath,
                    ProDuctionenterprise=request.GEtProductionBasicMess.ProDuctionenterprise,
                    ProDuctionImages=request.GEtProductionBasicMess.ProDuctionImages,
                    ProDuctionNum=request.GEtProductionBasicMess.ProDuctionNum
                };

               var GETUpdateData= _ProductionBsicMess.update( GTPro );
                query.data = GETUpdateData;
                query.MSG = "修改成功";

            }
            else
            {
                var list = _ProductionBsicMess.Add(request.GEtProductionBasicMess);
                if (list > 0)
                {
                    query.data = list;
                    query.MSG = "添加成功";
                }
            }

         

            return query;




        }
    }
}
